import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: tianchao
 * @Date: 2021/9/12 22:38
 * @Description:
 */
public class Test {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        List<String> list = new ArrayList<>();
        list.add("a");
        Class aClass = list.getClass();
        Method size = aClass.getDeclaredMethod("size");
        Object invoke = size.invoke(list);
        System.out.println(invoke);
        System.out.println(aClass.getSuperclass());
        aClass = aClass.getSuperclass();
        System.out.println(aClass.getGenericSuperclass());
        Type[] actualTypeArguments = ((ParameterizedType) aClass.getGenericSuperclass()).getActualTypeArguments();
        for (Type actualTypeArgument : actualTypeArguments) {
            System.out.println(actualTypeArgument.getTypeName());
        }

        C c = new C();
        System.out.println(c.getClass());
        System.out.println(c.getClass().getSuperclass());
        System.out.println(c.getClass().getSuperclass().getSuperclass());
        actualTypeArguments = ((ParameterizedType)c.getClass().getSuperclass().getGenericSuperclass()).getActualTypeArguments();
        for (Type actualTypeArgument : actualTypeArguments) {
            System.out.println(actualTypeArgument.getTypeName());
        }
    }
}

class A<T>{

}
class B<T> extends A<T>{

}
class C extends B<String>{

}
